home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Demos / Codeworks 0.94b3 / Codeworks® WWW Demo Doc. / Scripting Manual.doc / Scripting Manual.doc.rsrc / TEXT_144.txt < prev    next >
Encoding:
Text File  |  1995-05-01  |  1.6 KB  |  33 lines

  1. Control Structures  - While & Until
  2.  
  3.  While and until statements execute a block over and over again until a condition is satisfied.  For example:
  4.  
  5.         $ dice, rolls.
  6.         dice := 0.
  7.         rolls := 0.
  8.         until [ dice == 7 ] do [
  9.             dice := (choose 1 to 6) + (choose 1 to 6).
  10.             rolls := rolls + 1.
  11.         ].
  12.         "It took" && rolls.name && "rolls to roll a 7".
  13.  
  14.     When the until statement is executed, the expression dice == 7 is evaluated.  If it isn‚Äôt true, then the block is executed and the whole process repeated.  When the condition becomes true, then the until statement finishes.
  15.  
  16. !!    Note that the condition is in square brackets.  Actually, it is a small block.  The condition must be in square brackets because it is executed multiple times.
  17.  
  18.     The while statement works the same way, only it keeps executing the block while the condition is true and stops executing when the condition is false.  For example:
  19.  
  20.         $ n.
  21.         n := 1.
  22.         while [ (n fib) < 100 ] do [
  23.             n := n + 1.
  24.         ].
  25.         (n fib).name && "is the first Fibonacci number greater than 100"
  26.     
  27.  
  28. Infinite Loops
  29.     Be careful to ensure that the condition will eventually cause the loop to stop.  If you accidentally execute a statement that is never going to end (or if it‚Äôs just going to take too long), you can interrupt it.
  30.  
  31.     To interrupt a running script:
  32. 1.    Press the pen down anywhere near the lower left hand corner of the screen.  You should press within an inch of the corner.  You will have to hold the pen until the User Interrupt note appears.  This may take a few seconds.
  33. 2.    Tap Halt in the User Interrupt note.  After a few seconds, a debugger will open.  You can simply close it.